package com.rivulet.foreign.mapper;

import com.rivulet.foreign.pojo.Scholarship;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * {1.0版本之后的修改版奖学金表操作mapper}
 *
 * @author xujiac
 * @create 2021/8/18
 * @since 1.0.0
 */

@Component
public interface ScholarshipMapper {

    /**
     * 添加新的元组
     *
     * @param user_id
     * @param scholarship_type
     * @param curriculum
     * @param average_credit
     * @param gpa
     * @param reason
     * @param bonus_items_body
     * @param bonus_items_practice
     */
    @Insert("insert into t_scholarship " +
            "(user_id,scholarship_type,curriculum_number,average_credit,gpa,reason,bonus_items_body,bonus_items_practice)" +
            "values" +
            "(#{user_id},#{scholarship_type},#{curriculum_number},#{average_credit},#{gpa},#{reason},#{bonus_items_body},#{bonus_items_practice})")
    public void setScholarship(
            @Param("user_id")String user_id,
            @Param("scholarship_type")Integer scholarship_type,
            @Param("curriculum_number")Integer curriculum,
            @Param("average_credit")Double average_credit,
            @Param("gpa")Double gpa,
            @Param("reason")String reason,
            @Param("bonus_items_body")String bonus_items_body,
            @Param("bonus_items_practice")String bonus_items_practice
            );

    /**
     * 获取所有奖学金审批信息
     *
     * @return List<Scholarship>
     */
    @Select("select * from t_scholarship where is_yes is NULL")
    public List<Scholarship> getYetScholarship();

    /**
     * 查询指定user_id的奖学金信息
     *
     * @param user_id
     * @return
     */
    @Select("select * from t_scholarship where user_id =#{user_id}")
    public Scholarship getScholarshipById(@Param("user_id")String user_id);

    /**
     * 根据user_id更新表的advice,is_yes字段
     *
     * @param user_id
     * @param advice
     * @param is_yes
     */
    @Update("update t_scholarship set advice=#{advice},is_yes=#{is_yes} where user_id=#{user_id}")
    public void approveScholarship(
            @Param("user_id")String user_id,
            @Param("advice")String advice,
            @Param("is_yes")Integer is_yes
    );

    /**
     * 删除指定user_id的元组
     *
     * @param user_id
     */
    @Delete("delete from t_scholarship where user_id=#{user_id}")
    public void delScholarship(@Param("user_id")String user_id);

    /**
     * 查询具体的奖学金类型
     *
     * @param id
     * @return
     */
    @Select("select scholarship_type from r_scholarship where scholarship_id=#{scholarship_id}")
    public String getScholarshipType(@Param("scholarship_id")Integer id);

    /**
     * 查询所有的奖学金类型
     *
     * @return
     */
    @Select("select * from r_scholarship")
    public Map<Integer,String> getAllScholarshipType();

    /**
     * 添加新的奖学金类型
     *
     * @param id
     * @param type
     */
    @Insert("insert into r_scholarship (scholarship_id,scholarship_type) values (#{scholarship_id},#{scholarship_type})")
    public void setScholarshipType(@Param("scholarship_id")Integer id,@Param("scholarship_type")String type);

}
